package net.mikoo.seals.api.model.party;

import org.apache.commons.lang.StringUtils;

import net.mikoo.seals.api.model.BaseResponse;
import net.mikoo.seals.api.utility.ApiConstants;
import net.mikoo.seals.biz.model.PartyType;
import net.mikoo.seals.model.Company;
import net.mikoo.seals.model.Party;

public class PartyInfoResponse extends BaseResponse {

	private static final long serialVersionUID = 5942522994121733822L;

	private PartyInfo party;

	public PartyInfo getParty() {
		return party;
	}

	public void setParty(PartyInfo party) {
		this.party = party;
	}
	
	public static PartyInfoResponse valueOf(Party party, PartyType partyType) {
		PartyInfoResponse result = new PartyInfoResponse();
		if(party == null) {
			return result;
		}
		
		PartyInfo partyInfo = new PartyInfo();
		partyInfo.setLoginName(party.getPerson().getUserLoginId());
		partyInfo.setName(party.getPerson().getName());
		if(StringUtils.isNotBlank(party.getPerson().getPortrait())) {
			partyInfo.setPortrait(party.getPerson().getPortrait());
		}
		partyInfo.setType(partyType.getValue());
		partyInfo.setPartyId(party.getPartyId());
		partyInfo.setGender(party.getPerson().getGender());
		partyInfo.setMobile(party.getPerson().getMobile());
		partyInfo.setEmail(party.getPerson().getEmail());
		
		Company company = party.getCompany();
		if(company != null) {
			partyInfo.setCompanyId(company.getCompanyId());
			partyInfo.setCompanyName(company.getCompanyName());
		}
		
		result.setParty(partyInfo);
		
		return result;
	}
}
